<?php
	require("frmCookie.php");
	
	$iOpcion = $_GET[iOpcion];
	$iMensaje = $_GET[iMensaje];
?>
<html>
	<head>
    	<?php
		require("frmHeader.php");
		?>
		<script language="javascript" src="scripts/ajax.js"></script>
		<script language="javascript" src="scripts/validar.js"></script>
		<script language="javascript">
			
			function showHistory()
			{
				xmlHttp = GetXmlHttpObject();
				if (xmlHttp == null)
	  			{
	  				alert ("Your browser does not support AJAX!");
	  				return;
	  			}
	  			 
				var url = "ajaxHistorial.php";
				url = url + "?nroImei=" + frm.txtImei.value;
				url = url + "&nroLinea=" + frm.txtNroLinea.value;
				url = url + "&nroOrden=" + frm.txtNroOrden.value;
				url = url + "&sid=" + Math.random();
				xmlHttp.onreadystatechange = stateChangedHistory;
				xmlHttp.open("GET",url,true);
				xmlHttp.send(null);
			}
	
			function stateChangedHistory() 
			{ 
				if (xmlHttp.readyState == 4)
				{ 
					document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
					if(xmlHttp.responseText == "")
					{
						document.frm.submit();
					}
				}
			}
			
			function valida()
			{
				
				if((frm.txtImei.value == "") && (frm.txtNroLinea.value == "") && (frm.txtNroOrden.value == ""))
				{
					alert("Por favor ingrese alguno de los filtros de busqueda.");
					frm.txtNroLinea.focus();
					return false;
				}
				/*
				if(frm.txtImei.value != "")
				{
					if(IsNumeric(frm.txtImei.value) == false)
					{
						alert("El Imei solo puede contener numeros.");
						frm.txtImei.focus();
						return false;
					}
				}*/
				if(frm.txtNroLinea.value != "")
				{
					if(IsNumeric(frm.txtNroLinea.value) == false)
					{
						alert("El Nro de Linea solo puede contener numeros.");
						frm.txtNroLinea.focus();
						return false;
					}
				}
				if(frm.txtNroOrden.value != "")
				{
					if(IsNumeric(frm.txtNroOrden.value) == false)
					{
						alert("El Nro de Orden solo puede contener numeros.");
						frm.txtNroOrden.focus();
						return false;
					}
				}
				
				showHistory();
				
				return false;
			}
		</script>
	</head>
	<body>
    	<table cellpadding="0" cellspacing="0" align="center" class="tablaPrincipal">
        	<tr>
            	<td align="center">
                	<?php
					require("frmSession.php"); 
					
					//Redirecciona a SINPERMISOS.PHP en caso de no tener permisos
					switch ($iOpcion)
					{
						case 1:
						case 2:
						{
							
							if (!(in_array(18000, $_SESSION[permisos])))
							{
							?>
							  <script language="JavaScript" type="text/javascript">
							  <!--
							  window.location.href = "sinPermisos.php"
							  //-->
							  </script>
							<?php
							}
							$titulo = "Historial de un EQUIPO";
							break;
						}
						case 3:
						case 4:
						{
							if (!in_array(4102, $_SESSION[permisos]))
							{
							?>
							  <script language="JavaScript" type="text/javascript">
							  <!--
							  window.location.href = "sinPermisos.php"
							  //-->
							  </script>
							<?php
							}
							$titulo = "Proceso de Orden BATCH - BULK";
							break;
						}
						case 5:
						case 6:
						case 7:
						{
							if (!in_array(4103, $_SESSION[permisos]))
							{
							?>
							  <script language="JavaScript" type="text/javascript">
							  <!--
							  window.location.href = "sinPermisos.php"
							  //-->
							  </script>
							<?php
							}
							$titulo = "Proceso de Orden BATCH - BULK";
							break;
						}
					}
					
					?>
                </td>
            </tr>
            <tr>
            	<td align="center">
                	<?php
					require("frmTitulo.php");
					?>
                </td>
            </tr>
            <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
            	<td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="menuPrincipal">
                    	<tr>
                        	<td>
								<?php
                                require("frmMenu.php");
                                ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="tituloPantalla">
                    	<tr>
                        	<td align="center">
                            	<p class="texto" align="left"><?php echo $titulo; ?></p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="estadoPantalla">
                    	<tr>
                        	<td align="center">
                            	<p class="texto" align="left"><?php echo $mensaje; ?></p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="contenedorPrincipal">
                    	<tr>
                        	<td align="">
                        		<form name="frm" action="main.php?iOpcion=2" method="post" onSubmit="return valida();">
		                			<table>
		                				<tr>
		                					<td>Nro.Linea: </td>
		                					<td><input type="text" name="txtNroLinea" size="20" maxlength="20" /></td>
		                				</tr>
		                				<tr>
		                					<td>Imei: </td>
		                					<td><input type="text" name="txtImei" size="15" maxlength="15" /></td>
		                				</tr>
		                				<tr>
		                					<td>Nro.Orden: </td>
		                					<td><input type="text" name="txtNroOrden" size="15" maxlength="15" /></td>
		                				</tr>
		                				<tr>
		                					<td colspan="2" align="center"><div id="txtHint"></div></td>
		                				</tr>
		                				<tr>
		                					<td colspan="2" align="center"><input type="submit" name="cmdEnviar" value="Consultar"></td>
		                				</tr>
		                			</table>
        		            	</form>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
	</body>
</html>